1
從線性到結構化推理:鏈式思維的演進
AI012Lesson 4
00:00

從線性到結構化推理

推理的演進究竟是什麼?

推理的演進,代表了大型語言模型處理複雜任務方式的根本轉變。它標誌著模型從提供單一、連續的「意識流」,轉向探索複雜、多路徑的邏輯架構。鏈式思維(CoT)代表了大型語言模型處理複雜任務方式的根本轉變。它標誌著模型從提供單一、連續的「意識流」,轉向探索複雜、多路徑的邏輯架構。

為什麼要超越線性鏈式思維?

線性基線(標準鏈式思維):在標準鏈式思維中,模型按順序生成中間步驟。雖然對簡單的文字問題非常有效,但存在一個關鍵缺陷:如果早期出現錯誤,便無法回溯或探索其他解決方案。

現代推理轉變(「o1」模式):像 OpenAI o1 與 DeepSeek-R1 這樣的模型顯著延長了推理長度。它們在最終輸出前進行「數位對齊」與內部驗證,證明複雜問題需要刻意規劃,而非直覺猜測。

結構化推理如何運作

  • 思維程式(PoT)將推理與計算分離。模型不直接以文字解決數學問題,而是生成程式碼(例如 Python)來處理邏輯或數學任務。例如,要找出 $x^2 + 2x + 1 = 0$ 的根,模型會撰寫腳本,而非猜測代數解法。
  • 思維樹(ToT)允許模型分支出多個「思考」候選。模型評估這些分支並剔除死胡同,其運作方式類似於經典搜尋演算法(例如 A* 或蒙特卡洛樹搜尋)。
  • 思維圖(GoT)將推理視為一個網路。資訊可從多個獨立節點匯集,允許非線性依賴關係,即不同的思考路徑融合成單一結論。
關鍵洞見
將複雜問題分解為模組化的「思考節點」,使模型能超越簡單的下一個詞預測,走向有目的的規劃與驗證。
reasoning_logic.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Which reasoning structure is best suited for tasks requiring "look-ahead" planning and the ability to abandon dead-end ideas?
Linear Chain-of-Thought (CoT)
Tree-of-Thoughts (ToT)
Program of Thought (PoT)
Zero-Shot Prompting
Question 2
In the Program of Thought (PoT) framework, what performs the actual mathematical computation?
The LLM's internal weights
The Self-Attention mechanism
An external code interpreter or program execution
A dedicated math-only neural network
Challenge: Design a GoT Workflow
Apply Graph-of-Thoughts to a research summary task.
You are designing a Graph-of-Thought (GoT) workflow for an AI agent tasked with writing a comprehensive research summary.
Task 1
Create three independent thought nodes to analyze different aspects of the research paper.
Solution:
You would instantiate three parallel processes or prompts:
node_1 = analyze("Methodology")
node_2 = analyze("Results")
node_3 = analyze("Limitations")
Task 2
Create a final node that demonstrates the "Graph" nature by aggregating data from all three previous nodes.
Solution:
The final node takes the outputs of the previous independent nodes as its input, forming a graph structure rather than a simple tree or line.
synthesis_node = aggregate([node_1, node_2, node_3])
final_summary = generate_summary(synthesis_node)